﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PaperRenderingEngine;
using System.Diagnostics;

namespace t_PaperRenderingInterfaces
{
    [TestClass]
    public class WebAccessTest
    {
        [TestMethod]
        public void TestCTor()
        {
            var wa = new WebAccess();
        }

        [TestMethod]
        public void TestBadWebAddress()
        {
            var wa = new WebAccess();
            var result = wa.GetUriAsString(new Uri("http://www-d0.fnal.gov/www.funkycnninabox.com"));
            Assert.AreEqual("", result, "bad dns name shoudl give us a null");
        }

        [TestMethod]
        public void TestGoodURL()
        {
            var wa = new WebAccess();
            var result = wa.GetUriAsString(new Uri("http://www-d0.fnal.gov"));
            Assert.IsNotNull(result, "Expected to get somethign real back");
            Assert.IsTrue(result.StartsWith("<html>"), "expected the response to start with html!");
        }

        [TestMethod]
        public void TestGetUri()
        {
            var wa = new WebAccess();
            DateTime? when = wa.GetLastModificationTime(new Uri("https://twiki.cern.ch/twiki/pub/Atlas/MuonPerformancePublicPlots/run141749etc_phi.png"));
            Assert.IsTrue(when.HasValue, "Expecting the date to come back with a value!");
            Trace.WriteLine("The found date is " + when.Value.ToLongTimeString());
            Trace.WriteLine("The found date is " + when.Value.ToLongDateString());
        }

        [TestMethod]
        public void TestGetBadURL()
        {
            var wa = new WebAccess();
            var result = wa.GetUriAsString(new Uri("http://www-cdf.fnal.gov/physics/new/top/public/dilepton/testSM-dil/public.html"));
            Assert.IsNotNull(result, "Bad URL came back as null, not empty spaces!");
        }

    }
}
